#include "processbar.h"

const char * cyc="|/-\\";

// version1
void process()
{
    char buffer[NUM]={0};
    //memset(buffer,'\0',sizeof(buffer));
    
    int cnt = 0;
    char ch;
    buffer[0] = H;
    while(cnt <= 100)
    {
        printf("[%-100s][%d%%][%c]\r",buffer,cnt,cyc[cnt%4]);
        buffer[cnt++] = S;
        if(cnt<100)
            buffer[cnt] = H;
        fflush(stdout);
        usleep(100000);
    }
    printf("\n");
}


// version2

char buffer[NUM] = {0};

void process_flush(double rate)
{   
    static int cnt = 0;
    if(rate < 1.0)  buffer[0] = H;
    printf("[%-100s][%.2lf%%][%c]\r",buffer,rate,cyc[cnt%4]);
    fflush(stdout);
    buffer[(int)rate] = S;
    if((int)rate < 99)   
        buffer[(int)rate + 1] = H;
    cnt++;
    cnt%=4;
}

